package com.sugar.real.estate.module.business.controller.app.designplan;

import com.sugar.real.estate.framework.common.pojo.CommonResult;
import com.sugar.real.estate.framework.common.pojo.PageParam;
import com.sugar.real.estate.framework.common.pojo.PageResult;
import com.sugar.real.estate.module.business.controller.app.designplan.vo.AppDesignPlanDetailRespVO;
import com.sugar.real.estate.module.business.controller.app.designplan.vo.AppDesignPlanPageRespVO;
import com.sugar.real.estate.module.business.service.designplan.DesignPlanService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.validation.Valid;
import java.util.List;

import static com.sugar.real.estate.framework.common.pojo.CommonResult.success;

@Tag(name = "APP - 设计方案")
@RestController
@RequestMapping("/biz/design-plan")
@Validated
public class AppDesignPlanController {

    @Resource
    private DesignPlanService designPlanService;

    @GetMapping("/get")
    @Operation(summary = "获得设计方案")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PermitAll
    public CommonResult<AppDesignPlanDetailRespVO> getDesignPlan(@RequestParam("id") Long id) {
        return success(designPlanService.appGetDesignPlan(id));
    }

    @GetMapping("/list/{buildHouseId}")
    @Operation(summary = "根据建房ID获取该建房的设计方案")
    @PermitAll
    public CommonResult<List<AppDesignPlanPageRespVO>> getDesignPlanListByBuildHouseId(@PathVariable("buildHouseId") Long buildHouseId) {
        return success(designPlanService.getDesignPlanListByBuildHouseId(buildHouseId));
    }

    @GetMapping("/page")
    @Operation(summary = "获得设计方案分页")
    @PermitAll
    public CommonResult<PageResult<AppDesignPlanPageRespVO>> getDesignPlanPage(@Valid PageParam reqVO) {
        return success(designPlanService.appGetDesignPlanPage(reqVO));
    }
}